package c.x.jy.wexin.controller;

import c.x.jy.common.annotation.Login;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.service.service.CmsArticleDataService;
import c.x.jy.service.service.CmsArticleService;
import c.x.jy.service.service.CmsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-22 16:38:13
 */
@RestController
@RequestMapping("wechat/cmsarticle")
public class CmsArticleController  {
    @Autowired
    private CmsArticleService cmsArticleService;


    @Autowired
    private CmsCategoryService cmsCategoryService;

    @Autowired
    private CmsArticleDataService cmsArticleDataService;

    @Login
    @GetMapping("/article")
    public R article(@RequestParam Map<String, Object> params) {

        return R .put(new PageUtils(cmsArticleService.selectList( params)));
    }
    @Login
    @GetMapping("/articleforhome")
    public R articleforhome(String ids) {

        return R .put(cmsArticleService.selectListforHome(ids));
    }
    
    @Login
    @GetMapping("/articledetail")
    public R articledetail(Integer articleid) {

 
 
        return R .put(cmsArticleService.getArticleByID(articleid));
    }

    /**
     * 通过数据ID取文 章
     * @param id
     * @return
     */
 
    @Login
    @GetMapping("/articleData")
    public R articleData(Long id) {

        if(id==null)return R.error();

        cmsArticleService.updateHits(id);
        return R .put(cmsArticleDataService.getById(id));
    }

    /**
     * 通过文 章ID取
     * @param id
     * @return
     */
    @Login
    @GetMapping("/articleIdData")
    public R articleIdData(Integer id) {
        if(id==null)return R.error();
        return R .put(articleData( cmsArticleService.getById(id).getArticleDataId()));
    }

    @Login
    @GetMapping("/cmsCategory")
    public R cmsCategory(@RequestParam Map<String, Object> params) {

        return R .put(cmsCategoryService.selectList( params));
    }




}

